350-intersection-of-two-arrays-ii.py
problem: ---
problem:

Given two arrays, write a function to compute their intersection.

Example 1:
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]

Example 2:
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]

Note:
Each element in the result should appear as many times as it shows in both arrays.
The result can be in any order.
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
Add a colon at the end of line 8.
Replace `d.get(no)` with `d.get(no, 0)` on line 9.
Replace `or` with `and` in line 12.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:
On line 8, a colon is missing from the for-loop, causing it to not terminate. This is a syntactical bug that can be fixed by adding a colon at the end.
On line 9, if `no` is not found in `d`, then nothing is returned. This is incorrect behavior as d[no] could be an invalid integer. To solve this, set a default value in the `get` method.
On line 12, the code will append numbers to res even if they are present in only one of the input lists (nums1 or nums2). This is incorrect, and therefore, the condition should be `if no in d and d[no]`
---

-----------------------------------------------------------------------
line_no: ---
line_no:
8
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution:
2.     def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
3.         if len(nums2) > len(nums1):
4.           self.intersect(nums2, nums1)
5.         
6.         d = {}
7.         res = []
8.         for no in nums1
9.           d[no] = d.get(no) + 1
10.         
11.         for no in nums2:
12.           if no in d or d[no]:
13.             res.append(no)
14.             d[no] -= 1
15.         return res
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution:
2.     def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
3.         if len(nums2) > len(nums1):
4.           self.intersect(nums2, nums1)
5.         
6.         d = {}
7.         res = []
8.         for no in nums1:
9.           d[no] = d.get(no,0) + 1
10.         
11.         for no in nums2:
12.           if no in d and d[no]:
13.             res.append(no)
14.             d[no] -= 1
15.         return res
---

-----------------------------------------------------------------------
